from django.db import models
from hdiary.middleware import threadlocals
from django.contrib.auth.models import User


#class UserProfile(models.Model):
#    phone_numer = models.PhoneNumberField()
#    user = models.ForeignKey(User, unique=True)
#    class Admin:
#        pass

class FactorType(models.Model):
    slug = models.SlugField(prepopulate_from=("name", ))
    name = models.CharField(maxlength=100)
    description = models.TextField(blank = True)
    class Admin:
        pass

class FactorLevel(models.Model):
    patient = models.ForeignKey(User, blank = True, default = None)
    date = models.DateField()
    factor_type = models.ForeignKey(FactorType)
    def save(self):
        if self.patient_id is None:
            self.patient_id = threadlocals.get_current_user().id
        super(Reception, self).save()
    class Admin:
      pass
    
class AntigenType(models.Model):
    slug = models.SlugField(prepopulate_from=("name", ))
    name = models.CharField(maxlength=100)
    description = models.TextField(blank = True)
    impacts = models.ManyToManyRel(FactorType)
    class Admin:
        pass

class AntigenLevel(models.Model):
    patient = models.ForeignKey(User, blank = True, default = None)
    date = models.DateField()
    antigen_type = models.ForeignKey(AntigenType)
    def save(self):
        if self.patient_id is None:
            self.patient_id = threadlocals.get_current_user().id
        super(Reception, self).save()
    class Admin:
        pass
    

#class RegisterableModel(models.Model):
#  registration_date = models.DateField(auto_now_add = True)
#  registered_by = models.ForeignKey(User, blank = True, default = None)
#  def save(self):
#    if self.registered_by_id is None:
#      self.registered_by_id = threadlocals.get_current_user().id
#    super(RegisterableModel, self).save()
#  class Meta:
#    #someday they will implement it
#    #so far we have an empty table
#    #is_abstract = True
#    pass


